<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./template/template.xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://java.sun.com/jsf/html">

    <ui:define name="content">
        <p:panel header="films">
            <h:form id="form">
                <p:commandButton id="edit" value="Add film" action="#{mbFilm.navigationToFilmUpdate(null)}" ajax="false" immediate="true"/>
                <p:dataTable id="table" value="#{mbFilm.listFilm}" var="film">
                    <p:column headerText="Id">
                        <h:outputText value="#{film.idFilm}"/>
                    </p:column>
                    <p:column headerText="Name">
                        <p:commandLink  ajax="false" immediate="true" value="#{film.name}"
                                        action="#{mbFilm.navigationToFilmUpdate(film)}"/>
                    </p:column>
                    <p:column headerText="Duration">
                        <h:outputText value="#{film.duration}"/>
                    </p:column>
                    <p:column headerText="Genre">
                        <ui:repeat value="#{film.genreList}" var="g">
                            <h:outputText value="#{g.name}"/>
                        </ui:repeat>
                    </p:column>
                    <p:column headerText="Edit">
                        <p:commandLink  ajax="false" immediate="true"
                                        action="#{mbFilm.navigationToFilmUpdate(film)}">
                            <h:graphicImage value="icons/edit.png"/>
                        </p:commandLink>
                    </p:column>
                    <p:column headerText="Delete">
                        <p:commandLink actionListener="#{mbFilm.prepareFilm(film)}"
                                       id="deleteUser" oncomplete="dialogConfirmVar.show()"
                                       process="@this" update=":formdialog:dialogconfirm" >
                            <h:graphicImage  value="icons/delete.png"/>
                        </p:commandLink>
                    </p:column>

                </p:dataTable>
            </h:form>
            <h:form id="formdialog">
                <p:confirmDialog id="dialogconfirm" message="Are you sure that you want to delete this film ?"
                                 header="Confirm" severity="alert" widgetVar="dialogConfirmVar">  
                    <p:commandButton id="confirm" value="Yes " update=":form:table,formdialog" oncomplete="dialogConfirmVar.hide()"  
                                     actionListener="#{mbFilm.deleteFilm}" process="@this" />  
                    <p:commandButton id="decline" value="Not " onclick="dialogConfirmVar.hide()" type="button" />   
                </p:confirmDialog>
            </h:form>
        </p:panel>
    </ui:define>
</ui:composition>
